﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Microsoft.Win32;

namespace Douban.Core.Helpers
{
    public class WindowPositionHelper
    {
        private static string _registryPath = @"Software\豆Q\WindowBounds\";
        private const string RegistryKey = "1001";

        public static void Save(Window window)
        {
            RegistryKey key = Registry.CurrentUser.CreateSubKey(_registryPath + RegistryKey);
            key.SetValue("Bounds", window.RestoreBounds.ToString());
        }

        public static void SetSize(Window window)
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(_registryPath + RegistryKey);

            if(key != null)
            {
                Rect rect = Rect.Parse(key.GetValue("Bounds").ToString());
                window.Top = rect.Top;
                window.Left = rect.Left;
                window.Width = rect.Width;
                window.Height = rect.Height;
            }
        }
    }
}
